﻿using Collection.Entities;
using Super.Collection.Entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Super.Collection.Core.Providers
{
    /// <summary>
    /// 基本数据提供类
    /// </summary>
    public abstract class DataProvider : IProvider
    {
        /// <summary>
        /// 获取公告接口
        /// </summary>
        /// <returns>返回公告列表</returns>
        public abstract List<Announcement> GetAnnouncements(string url, Encoding encoding);

		public abstract NLotteryDraw GetLatestLotteryDraw();

        /// <summary>
        /// 以指定的编码格式获取文档
        /// </summary>
        /// <param name="url">提供者的地址</param>
        /// <param name="encoding">文档解析的编码</param>
        /// <returns>Html文档</returns>
        public string GetDocument(string url, Encoding encoding)
        {
            MemoryStream stream = HttpLoader.Instance.SaveResponseToMemory(url);
            byte[] b = stream.ToArray();
            return encoding.GetString(b, 0, b.Length);
        }

        /// <summary>
        /// 获取正则表达式匹配的结果集合
        /// </summary>
        /// <param name="content">字符串内容</param>
        /// <param name="regex">正则表达式</param>
        /// <returns>匹配结果集合</returns>
        public MatchCollection GetMatchCollections(string content, string regex)
        {
            return Regex.Matches(content, regex, RegexOptions.IgnoreCase);
        }
	}
}
